package cmd

import (
	"context"
	"gitee.com/marcellos/wow-updte-ip/internal/crontab/lookup"
	"gitee.com/marcellos/wow-updte-ip/internal/dao"

	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/os/gcmd"

	"gitee.com/marcellos/wow-updte-ip/internal/controller/hello"
)

var (
	Main = gcmd.Command{
		Name:  "main",
		Usage: "main",
		Brief: "start http server",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			s := g.Server()
			s.Group("/", func(group *ghttp.RouterGroup) {
				group.Middleware(ghttp.MiddlewareHandlerResponse)
				group.Bind(
					hello.NewV1(),
				)
			})

			dao.NewConnect(ctx)

			go lookup.NewIp().Run(ctx)

			s.Run()
			return nil
		},
	}
)
